const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');

const UserLike = sequelize.define('UserLike', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'users',
      key: 'id'
    }
  },
  shared_image_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'shared_images',
      key: 'id'
    }
  }
}, {
  tableName: 'UserLikes',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: false,  // 禁用 updatedAt，因为点赞记录不需要更新时间
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'shared_image_id']
    }
  ]
});

module.exports = UserLike;